from langchain import OpenAI, SQLDatabase, SQLDatabaseChain

db = SQLDatabase.from_uri(
    "mysql+pymysql://root:password@115.159.119.116:3306/openai_demo",
    include_tables=['data_wide_s_trade'],
    sample_rows_in_table_info=2
    )
llm = OpenAI(temperature=0)


db_chain = SQLDatabaseChain.from_llm(llm=llm, db=db, verbose=True, use_query_checker=True)
result = db_chain.run("今年每个项目签约了多少合同?")

print(result)
